#define _GNU_SOURCE//如果不定义这个，gettid()会报错
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>

void *first_thread(void *arg)
{
    //char *data = (char *)arg;
    printf("first线程(%d)开始执行,arg = %s\n",gettid(),(char *)arg);
    return "atguigu";
}

void *second_thread(void *arg)
{
    //int value = *(int *)arg;
    printf("second线程(%d)开始执行,arg = %d\n",gettid(),*(int *)arg);
    return (void *)12;
}

int main(int argc, char *argv[])
{
    printf("main 线程(%d)开始执行\n",gettid());
    //创建两个分线程
    pthread_t first_pt , second_pt;

    //创建第一个线程
    pthread_create(&first_pt,NULL,first_thread,"abc");

    int value = 100;
    //创建第二个线程
    pthread_create(&second_pt,NULL,second_thread,&value);

    printf("main 线程(%d)继续执行  first_pt=%ld , second_pt=%ld\n",
    gettid(), first_pt,second_pt);

    //等待两个线程执行完毕
    char *first_result;
    int second_result;
    pthread_join(first_pt,(void **)&first_result);
    pthread_join(second_pt,&second_result);
    printf("first_result = %s , second_result =%d \n",first_result,second_result);

    printf("main 线程(%d)结束执行\n",gettid());

    return 0;
}